<template>
  <div class="privacy-policy">
    <div class="page-header">
      <div class="container">
        <h1 class="page-title">隐私政策</h1>
        <p class="page-subtitle">我们重视您的隐私保护</p>
      </div>
    </div>
    
    <div class="container">
      <div class="content-section">
        <!-- 加载状态 -->
        <div v-if="loading" class="loading-container">
          <el-skeleton :rows="10" animated />
        </div>
        
        <!-- 内容 -->
        <div v-else class="policy-content">
          <div v-html="policyData.content" class="policy-text"></div>
          <div v-if="policyData.lastUpdate" class="last-update">
            <p>最后更新时间：{{ policyData.lastUpdate }}</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { ref, onMounted } from 'vue'
import request from '@/utils/request'

export default {
  name: 'PrivacyPolicy',
  setup() {
    const loading = ref(true)
    const policyData = ref({
      title: '隐私政策',
      content: '',
      lastUpdate: ''
    })
    
    // 加载隐私政策内容
    const loadPrivacyPolicy = async () => {
      try {
        loading.value = true
        const response = await request.get('/site/privacy-policy')
        if (response && response.code === '200') {
          policyData.value = response.data
        } else {
          // 使用默认内容
          policyData.value = {
            title: '隐私政策',
            content: `
              <h2>隐私政策</h2>
              <p>我们重视您的隐私保护，本隐私政策说明了我们如何收集、使用和保护您的个人信息。</p>
              
              <h3>1. 信息收集</h3>
              <p>我们可能收集以下类型的信息：</p>
              <ul>
                <li>您主动提供的信息，如注册信息、联系信息等</li>
                <li>自动收集的信息，如访问日志、设备信息等</li>
                <li>第三方提供的信息</li>
              </ul>
              
              <h3>2. 信息使用</h3>
              <p>我们使用收集的信息用于：</p>
              <ul>
                <li>提供和改进我们的服务</li>
                <li>与您沟通</li>
                <li>遵守法律义务</li>
              </ul>
              
              <h3>3. 信息保护</h3>
              <p>我们采取适当的技术和组织措施来保护您的个人信息安全。</p>
              
              <h3>4. 联系我们</h3>
              <p>如果您对本隐私政策有任何疑问，请通过联系我们页面与我们联系。</p>
            `,
            lastUpdate: new Date().toLocaleDateString()
          }
        }
      } catch (error) {
        console.error('加载隐私政策失败:', error)
        // 使用默认内容
        policyData.value = {
          title: '隐私政策',
          content: '<p>隐私政策内容加载失败，请稍后重试。</p>',
          lastUpdate: ''
        }
      } finally {
        loading.value = false
      }
    }
    
    onMounted(() => {
      loadPrivacyPolicy()
    })
    
    return {
      loading,
      policyData
    }
  }
}
</script>

<style scoped>
.privacy-policy {
  min-height: 100vh;
  background: linear-gradient(135deg, #320063 0%, #4a0a8a 100%);
}

.page-header {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  padding: 120px 0 80px 0;
  margin-top: 0;
  text-align: center;
  color: white;
}

.page-title {
  font-size: 3rem;
  font-weight: 700;
  margin-bottom: 1rem;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.page-subtitle {
  font-size: 1.2rem;
  opacity: 0.9;
  margin-bottom: 0;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.content-section {
  background: white;
  border-radius: 20px;
  padding: 3rem;
  margin: 2rem 0;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
}

.loading-container {
  padding: 2rem 0;
}

.policy-content {
  color: #333;
  line-height: 1.8;
}

.policy-text {
  font-size: 1.1rem;
  margin-bottom: 2rem;
}

.policy-text :deep(h1),
.policy-text :deep(h2),
.policy-text :deep(h3) {
  color: #333;
  margin: 2rem 0 1rem 0;
  font-weight: 600;
}

.policy-text :deep(h1) {
  font-size: 2rem;
  border-bottom: 2px solid #667eea;
  padding-bottom: 0.5rem;
}

.policy-text :deep(h2) {
  font-size: 1.5rem;
  color: #667eea;
}

.policy-text :deep(h3) {
  font-size: 1.3rem;
  color: #555;
}

.policy-text :deep(p) {
  margin-bottom: 1rem;
  text-align: justify;
}

.policy-text :deep(ul),
.policy-text :deep(ol) {
  margin: 1rem 0;
  padding-left: 2rem;
}

.policy-text :deep(li) {
  margin-bottom: 0.5rem;
}

.last-update {
  border-top: 1px solid #eee;
  padding-top: 1rem;
  margin-top: 2rem;
  text-align: right;
  color: #666;
  font-size: 0.9rem;
}

@media (max-width: 768px) {
  .page-title {
    font-size: 2rem;
  }
  
  .content-section {
    padding: 2rem;
    margin: 1rem 0;
  }
  
  .policy-text {
    font-size: 1rem;
  }
}
</style>
